package com.wang.sort;

//bubbleSort  冒泡排序
public class Demo2_BubbleSort {
    public static void bubbleSort(int[] arr){
        if(arr == null || arr.length <2){
            return;
        }
        for (int i = arr.length-1; i >0 ; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[i] >arr[i+1]){
                    swap(arr,i,i+1);
                }
            }
        }

    }
    public static void swap(int[] arr,int i,int j){
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }


}
